package com.ssm.zyn.service.impl;

import com.ssm.zyn.dao.TestquestionMapper;
import com.ssm.zyn.eo.TestQuestionEOpage;
import com.ssm.zyn.model.TestQuestion;
import com.ssm.zyn.service.TestquestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TestquestionServiceImpl implements TestquestionService {
    @Autowired
    private TestquestionMapper testquestionMapper;
    @Override
    public int AddTestquestion(TestQuestion testQuestion) {
        int returnInt=0;
        /**1.业务的判断
         * (1)角色名称不能重复
         */
        //(1)判断角色
        int testIdCount = testquestionMapper.getTestIdCount(testQuestion.getTestid());
        if (testIdCount < 1) {
            //2.数据的添加
            int addtestIdInt = testquestionMapper.insertTestquestion(testQuestion);
            //3.返回值的设置
            returnInt = addtestIdInt;
        } else {
            returnInt = -1;//有相同的
        }

        return returnInt;
    }

    @Override
    public int UpdateTestquestion(TestQuestion testQuestion) {
        int isUpdate=0;
        try {
            isUpdate = testquestionMapper.updateTestQuestion(testQuestion);
        } catch (Exception e) {
            isUpdate = -1;
            //打印更新时报错的情况
            System.out.println("更新角色信息时执行SQL报错的原因为"+e.getMessage());
        }
        return isUpdate;
    }

    @Override
    public int DeleteTestquestion(int testqid) {
        int delTesttable=0;
        try{
            delTesttable=testquestionMapper.delTestQuestiom(testqid);
        }catch (Exception e){
            delTesttable=-1;
            System.out.println("删除班级信息时执行SQL报错，信息为"+e.getMessage());
        }
        return delTesttable;
    }

    @Override
    public List<TestQuestionEOpage> getWhereAll(TestQuestionEOpage testQuestionEOpage) {
        List<TestQuestionEOpage> listTestQuestion=testquestionMapper.getWhereAll(testQuestionEOpage);
        return listTestQuestion;
    }
}
